<?php
namespace app\admin\controller\member;

use app\admin\controller\Controller;
use app\admin\model\Grade as GradeModel;

class Grade extends Controller
{
    protected $model;
    /**
     * 初始化
     * @access public
     */
    public function initialize()
    {
        // 控制器初始化
        $this->model = new GradeModel;
    }
    
    // 会员等级列表
    public function list(){
        return $this->renderSuccess($this->model->getList());
    }

    // 添加会员等级
    public function add(){
        if($this->model->add($this->request->only(['grade_name','image_id','weight','describes','upgrade','discount','status'])) !== false)
        {
            return $this->renderSuccess('添加成功!');
        }
        return $this->renderError($this->model->getError()??'修改失败!');
    }

    // 修改会员等级
    public function edit(){
        if($this->model->edit($this->request->only(['grade_id','grade_name','image_id','weight','describes','upgrade','discount','status'])) !== false)
        {
            return $this->renderSuccess('修改成功!');
        }
        return $this->renderError($this->model->getError()??'修改失败!');
    }

    // 删除会员等级
    public function delete(){
        if($this->model->setDelete($this->request->only(['grade_id'])) !== false)
        {
            return $this->renderSuccess('添加成功!');
        }
        return $this->renderError($this->model->getError()??'修改失败!');
    }
}